home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / SDDOS.INS < prev    next >
Text File  |  1987-11-20  |  8KB  |  322 lines

  1. SafetyPad       Db 640 dup(0)
  2.  
  3. Install:
  4.  
  5.  
  6. ;
  7. ;  We want to see if help or the internal stack is being used.
  8. ;
  9.  
  10.       Mov    SI,081
  11.       Call StripBlanks
  12.  
  13.       ES Cmp B [SI],CR               ; end of inputs?
  14.       Je     Envi                    ; if so then move on
  15.  
  16.       ES Cmp B [SI],'-'              ; internal stack or not?
  17.       If e Mov StackFlag,0           ; if '-' found no stack
  18.  
  19.       ES Cmp B [SI],'+'              ; storing help or not ?
  20.       If e Mov HelpFlag,0            ; if '+' found no help
  21.  
  22.       Push     SI
  23.       Inc      SI
  24.       Call StripBlanks
  25.  
  26.       ES Cmp B [SI],CR               ; end of inputs?
  27.       Je     Envi                    ; if so then move on
  28.  
  29.       ES Cmp B [SI],'-'              ; internal stack or not?
  30.       If e Mov StackFlag,0           ; if '-' found no stack
  31.  
  32.       ES Cmp B [SI],'+'              ; storing help or not ?
  33.       If e Mov HelpFlag,0            ; if '+' found no help
  34.  
  35. ;
  36. ;  Now let's see if there is a configuration file on the command line.
  37. ;
  38.       Pop    SI
  39.  
  40.       Cmp    StackFlag,0             ; if no stack then ignore config file
  41.       Je     Envi
  42.  
  43.       Push   SI
  44.  
  45.       Mov    DI,SI
  46.       Mov    AL,':'
  47.       Mov    CX,64
  48.  
  49.       Repne  Scasb
  50.       Jne    WhichOne
  51.  
  52.       Sub    DI,2
  53.       Mov    SI,DI
  54.       Mov    DI,Offset ConfigBuffer
  55.  
  56.    CED1:
  57.       Lodsb
  58.  
  59.       Cmp    AL,CR
  60.       Je     WhichOne
  61.  
  62.       Cmp    AL,' '
  63.       Je     WhichOne
  64.  
  65.       Cmp    AL,'a'                  ; lowercase letter?
  66.       If ae Xor AL,020               ; if so make upper case
  67.  
  68.       Stosb
  69.       Jmp    CED1
  70.  
  71. WhichOne:
  72.       Pop    SI
  73.  
  74.  
  75. ;
  76. ;  Now we deallocate our environment block and free it up for other programs
  77. ;
  78.    Envi:
  79.       Mov    AH,049                  ; release memory call to DOS
  80.       Mov    ES,[02C]                ; set ES to environment
  81.       Int    021                     ; call DOS
  82.       Mov    ES,CS                   ; restore ES
  83. ;
  84. ;  Based on the variable HelpFlag we determine how much memory to
  85. ;  allocate and TSR.  We will begin by assuming help will be installed
  86. ;
  87.  
  88.       Mov    DX,ProgramEndH          ; set DX to include help
  89.       Cmp    HelpFlag,1              ; are we supposed to include help?
  90.       If ne Mov DX,DtaAreaEnd        ; if not change DX
  91.  
  92.       Mov    StackAddress,DX
  93.       Cmp    StackFlag,1             ; what about the internal stack?
  94.                                      ; if flag set then add 640 bytes for
  95.       Jne    TSR                     ; storage
  96.  
  97. ;
  98. ;  We are going to use the internal stack so let's clean it out
  99. ;
  100.  
  101.       Mov    DI,DX
  102.       Mov    CX,640
  103.       Shr    CX,1
  104.       Mov    AX,0
  105.     C1:
  106.       Stosw
  107.       Loop   C1
  108.  
  109. ;
  110. ;  Up DX by the size of the buffer. (DX tells DOS how much mem. to TSR)
  111. ;
  112.  
  113.       Cld
  114.       Add    DX,640
  115.  
  116. ;
  117. ;  Last thing... if we have a config file read it into stack - if we have
  118. ;  a stack .......
  119. ;
  120.  
  121.       Cmp    B [ConfigBuffer],0
  122.  
  123.       Je     TSR
  124.  
  125.       Push   DX
  126.       Call ReadConfigFile
  127.       Pop    DX
  128.  
  129.   TSR:
  130.       Push   DX
  131.  
  132.         MOV     AX,03521
  133.         INT     021
  134.  
  135.         MOV     INT_21Off,BX
  136.         MOV     INT_21Seg,ES
  137.  
  138.         MOV     AX,02521
  139.         MOV     DX,OFFSET New_INT_21
  140.         INT     021
  141.  
  142.       Cld
  143.       Mov    DX,Offset Version       ; display version.
  144.       Call PrintS
  145.  
  146.       Pop    DX
  147.       Int    027                     ; terminate and stay resident
  148.  
  149.  
  150. ;---------------------------------------------------------------------------;
  151. ; ReadConfigFile                                                            ;
  152. ;                                                                           ;
  153. ;     ReadConfigFile checks to see if a config file exits and if it does    ;
  154. ;     reads the file and places the data in the internal stack.             ;
  155. ;                                                                           ;
  156. ;---------------------------------------------------------------------------;
  157.  
  158. OpenError       Db 'Error opening Config file',CR,LF,Stopper
  159.  
  160. ReadError       Db 'Error reading Config file.  Check format and size.',CR,LF,Stopper
  161.  
  162. DataError       Db 'Data error in Config file.  Check format, is it ascii ?',CR,LF,Stopper
  163.  
  164. ConfigBuffer    db 64 dup(0)
  165.  
  166. ConfigHandle    Dw ?
  167.  
  168. ;
  169. ;  To begin we verify that there is a configuration file in the buffer.  If
  170. ;  there is not then we leave.
  171. ;
  172.  
  173. ReadConfigFile:
  174. ;
  175. ;  We begin by attemptint to open the configuration file.
  176. ;
  177.       Mov    AL,0                       ; read access (no sharing)
  178.       Mov    DX,Offset ConfigBuffer     ; file name
  179.       Mov    AH,03D                     ; open file
  180.       Int    021
  181.  
  182.       Jnc    Opened
  183.  
  184. ;
  185. ;  If we get here we have an error opening the config file.
  186. ;
  187.  
  188.       Mov    Errlvl,10
  189.       Mov    DX,Offset OpenError
  190.       Call PrintS
  191.       Jmp    ExitDOS
  192.  
  193. ;
  194. ;  With successfull opening we now read the configuration file into memory.
  195. ;  We will assume it is less than 2048 bytes long and put it in memory where
  196. ;  the TheEND procedure is.
  197. ;
  198.  
  199. Opened:
  200.       Mov    ConfigHandle,AX            ; save handle for closing file
  201.  
  202. ;
  203. ;  Read from the config file.
  204. ;
  205.  
  206.       Mov    BX,ConfigHandle            ; read from config file
  207.       Mov    CX,2048                    ; read 2048 bytes
  208.       Mov    DX,Offset TheEND           ; put info at the end
  209.       Mov    AH,03F                     ; read file
  210.       Int    021
  211.  
  212. ;
  213. ;  If the carry flag is not set we are ready to go.
  214. ;
  215.  
  216.       Jnc    Close
  217.  
  218.       Mov    Errlvl,11
  219.       Mov    DX,Offset ReadError
  220.       Call PrintS
  221.       Jmp    ExitDOS
  222.  
  223. ;
  224. ;  Now, let's close the file before we go any further
  225. ;
  226.  
  227. Close:
  228.       Mov    BX,ConfigHandle            ; config file
  229.       Mov    AH,03E                     ; close it
  230.       Int    021
  231.  
  232. ;
  233. ;  Now we process the configuration information for the internal stack
  234. ;
  235.  
  236.       Mov    SI,Offset TheEND           ; point SI to configuration info
  237.  
  238. ;
  239. ;  RCF is the overall loop.  The program comes here at the begining of
  240. ;  each stack entry.
  241. ;
  242.  
  243.    RCF:
  244.       Lodsb
  245.  
  246.       Cmp    AL,26                      ; end of file mark ?
  247.       Je     ExitRCF                    ; yes, leave
  248.  
  249.       Sub    AL,030                     ; convert ascii
  250.       Cmp    AL,0A                      ; if it's between 0 and 9 we are ok.
  251.       If b Cmp AL,0
  252.       Jae    RCF1
  253.  
  254. ;
  255. ;  If the file is not in the proper format - 0=\....CRLF - then ERROR !
  256. ;
  257.  
  258.       Mov    Errlvl,12                  ; error in file format.
  259.       Mov    Dx,Offset DataError
  260.       Call PrintS
  261.       Jmp    ExitDOS
  262.  
  263. ;
  264. ;  We have a good format (ie AL contains a stack number) so we find the
  265. ;  appropriate offset into the internal stack buffer and make sure the
  266. ;  number is followed by an = sign.
  267. ;
  268.  
  269.    RCF1:
  270.  
  271.       Push   SI                         ; save SI
  272.       Call StackBufferPos               ; get offset into stack buffer
  273.       Mov    DI,SI                      ; point DI to offset
  274.       Pop    SI                         ; get SI back
  275.  
  276.       Lodsb                             ; get next character in file
  277.  
  278.       Cmp    AL,'='
  279.       Je     RCF2
  280.  
  281. ;
  282. ;  If the number is not followed by an = sign ERROR !
  283. ;
  284.       Mov    Errlvl,12                  ; error in file format.
  285.       Mov    Dx,Offset DataError
  286.       Call PrintS
  287.       Jmp    ExitDOS
  288.  
  289. ;
  290. ;  Now we process this stack entry.
  291. ;
  292.  
  293.    RCF2:
  294.       Lodsb                          ; get character
  295.  
  296.       Cmp    AL,CR                   ; is it the end of a line (CR) ?
  297.       Je     RCF3                    ; if so get out of loop
  298.  
  299.       Cmp    AL,'a'                  ; lowercase letter?
  300.       If ae Xor AL,020               ; if so make upper case
  301.  
  302.       Stosb                          ; store character
  303.  
  304.       Jmp    RCF2                    ; go get the next character
  305.  
  306.    RCF3:
  307.  
  308.       Inc    SI                      ; move SI past the LF character in the file
  309.       Jmp    RCF                     ; go get the next stack entry from the file
  310.  
  311. ExitRCF:
  312.       Ret
  313.  
  314.  
  315. ExitDOS:
  316.       Mov     AL,Errlvl